/**
 * 
 */
package com.manthano.applogin.authorization.handlers;

import java.io.IOException;
import java.util.Properties;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.authentication.AuthenticationFailureHandler;

import com.manthano.applogin.management.util.PropertyConfigUtil;

/**
 * @author Dell
 */
public class UserAuthenticationFailureHandler implements AuthenticationFailureHandler
{
	@Override
	public void onAuthenticationFailure(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse,
			AuthenticationException e) throws IOException, ServletException
	{
		String message = "LoginUser is not registered or Password is wrong";
		httpServletRequest.getSession().setAttribute("message", message + " : " + e.getLocalizedMessage());
		Properties properties = PropertyConfigUtil.getLoginProperties();
		httpServletResponse.sendRedirect(httpServletRequest.getContextPath()
				+ properties.getProperty("AUTHENTICATION_FAILURE_URL"));
	}
}
